import axios from "axios";
import store from "@/store"
import router from "@/router"

export const devUrl = 'http://8.134.169.207:8000'

const request = axios.create({
    //前缀地址
    baseURL: '/api',
    timeout: 5000,
})

// -------------------------请求拦截器
request.interceptors.request.use(aaa => {
    // 存token
    let token = store.state.user.token; 
    aaa.headers['token'] = token
    return aaa//拦截了，这里要原封不动的返回
}, err => {
    return err
    console.log(err);
})


// -------------------------响应拦截器
request.interceptors.response.use(res => {
    // 如果token无效，清空user的权限表并router.history.go(0)
    // 如果未请求成功，返回错误信息，并提示
  
    return res.data
}, err => {
    return err
    console.log(err);
})



export default request


